<?php namespace Home\Controller;
use Hdphp\Controller\Controller;
use Common\Model\User;
use Common\Model\Log;
class MemberController extends Controller{
	public function reg(){
		if(IS_AJAX){
			$userModel=new User();
			if(!$userModel->store()){
				$this->ajax(['status'=>false,'message'=>$userModel->getError()]);
			}
			else{
				$this->ajax(['status'=>true,'message'=>'注册成功']);
			}
		}
		
		View::make();
	}
	public function login(){
		if(IS_AJAX){
			$logModel=new Log();
			if(!$logModel->log()){
				$this->ajax(['status'=>false,'message'=>$logModel->getError()]);
			}
			else{
				$username=Q('post.username');
				$_SESSION['username'] = $username;
				$this->ajax(['status'=>true,'message'=>'登录成功']);
			}
		}
		
		View::make();
	}
	public function code(){
		Code::make();
	}
	public function out(){
		session_unset();
		session_destroy();
		View::success("退出成功",U('Index/index'));
	}
}